<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [
            { code: "China", name: "xiaohuai" },
            { code: "Africa", name: "neiLuoBi" },
            { code: "Asia", name: "hanGuo" },
            { code: "China", name: "tnnyang" },
            { code: "Africa", name: "nanFei" },
            { code: "China", name: "yangMan" }
        ]
        // [
        //     {
        //         code: china,
        //         list: [
        //             {name: 'yanman'}
        //             {name: 'yanman'}
        //             {name: 'yanman'}
        //         ]
        //     }
        // ]
        const temp = {}
        const list = []
        arr.forEach(item => {
            temp[item.code] = []
        })
        // console.log(temp)
        arr.forEach(item => {
            temp[item.code].push(
                {
                    name: item.name
                }
            )
        })
        console.log(temp)
        Object.keys(temp).forEach(el => {
            list.push({
                code: el,
                childList: temp[el]
            })
        })
        console.log(list)
    </script>
</body>

</html>